Purpose: Data
Hiding, Constructors, Destructors, Friends
Points: 25
Instructor: Dana
Steil
Turn In: All
Files in Easel
Files: String.h, String.cpp, StringIterator.h,
StringIterator.cpp, Test.cpp
String Assignment
Part 1.a
Fix all mistakes from strings part 2.
Part 1.b
Modify your String class from assignment 4 to make StringIterator a friend.
Part 2 Create a class named StringIterator with the following:
Variables:
int index; // The current index in focus for a given String
const String& string; //A reference to the string to iterate
Or or
const String* pString; //A pointer to the string to iterate
Functions:
StringIterator(const String& stringToIterate); //Make the index = 0
//Maintain a reference or pointer the stringToIterate
char currentCharacter(); //return \0 if there is not a current character
bool atWhiteSpace(); //return true if the current character is white space (‘ ‘,\n,\r,\f,\v,\t)
//the function that does this is “isspace(char c)” in the cctype library
char nextCharacter(); //return \0 if there is not a next character
char previousCharacter(); //return \0 if there is not a previous character
bool moveForward(int CharactersToMove = 1); //return false if it can not make the move
bool movePrevious(int CharactersToMove = 1); //return false if it can not make the move
bool moveToNextWord(); // return false if it can not make the move
bool moveToPreviousWord(); // return false if it can not make the move
void moveToFront();
void moveToEnd();
String currentWord(); //return a new String containing the word the Iterator currently resides in
//if it is currently on white space just use the one white space character
Later we will take care of a referenced String dieing without the Iterator knowing about it.